Mac GUI

How to Use the Hard Disk 20 with Mac 128K

Print this article



The Hard Disk 20 seems to be a popular subject around here. How many articles have I written so far on this thing? Well here's another one to satisfy the Mac 512K Blog's mission of taking the 512K Macintosh to its limits. But in this case, the Mac 128K is in the spotlight.

Probably every regular reader of the Mac 512K Blog knows that the Hard Disk 20 is not supported on the original Macintosh 128K, just like everyone knows that the Mac 512K can't run System 6. Apple told us that we can't use the Hard Disk 20 on the Mac 128K, but we are going to ignore what Apple said 35 years ago and do it anyway. Razz

Let's take stock of what we know so far.


Hard Disk 20 + Mac 128K, the Story Thus Far

I have never owned an original 128K Macintosh, but I had custody of one for a few weeks in fall 2017. In my very first Macintosh Hard Disk 20 article, way down near the end, I recorded some of my observations of using an HD20 and a Mac 128K. I will summarize what I discovered:

  • When booting the HD20 Startup disk, the phrase "Hard Disk 20 Startup" does not appear in the Welcome to Macintosh dialog box, and the Hard Disk 20 icon does not show on the Finder desktop.

  • Both HD Diag and HD20 Test, the utilities for the HD20, work on the Mac 128K and can access data stored on the Hard Disk 20.

  • If you replace the original 64K ROMs in the Mac 128K with the new Mac Plus 128K ROMs, you get a Mac 128Ke, and this configuration supports the Hard Disk 20 and 800K double-sided drive just like a Mac 512Ke.

Now from these three bullet points, the solution is obvious: simply put the new 128K ROMs in the Mac 128K, and now it will support the Hard Disk 20! Easy! Very Happy

Not so fast. That was too easy. Our goal is to use an HD20 with the original 64K ROM in the Mac 128K.


Loading the Hard Disk 20 File

In the recent article on Macintosh Startup Revealed, I showed how the Hard Disk 20 file is loaded by code in System file versions 2.1 and later during startup. Its three PTCH resources are each loaded into the system heap.

The Hard Disk 20 file contains an improved .Sony disk driver called SonyDCD, as well as RAM-based HFS. Two checks in the System file ensure that the HD20 code is loaded on only one model of Macintosh in the entire world: the Macintosh 512K.

Here are those few lines of code:
Code:
; Load Hard Disk 20, from System file 2.1
   MOVEM.L   D2-D7/A2-A6,-(SP)      ; save registers
   CMPI.W   #08,MemTop         ; check memory size
   BLT   Done            ; 128K is not enough
   TST.W   ROM85            ; new ROM?
   BPL   Done            ; yes, so nothing to do

The first CMPI.W instruction checks memory size. If the Mac has only 128K of RAM, it will fail this check. The second check is for the presence of the new 128K ROM. If the Mac does have the new ROM, this check fails. There is no need to load the Hard Disk 20 file on a Mac 512Ke, Plus, or later model because these ROMs already have the SonyDCD driver and HFS built-in.

The only model of Mac that has 512K of RAM, but not the new 128K ROM is the Mac 512K, thus the Hard Disk 20 file is only ever loaded on this model.

But it wasn't always going to be that way, as a comment in the HFS source code suggests. This comment, dated May 1985, refers to a change made "to allow use on 128K machines." Furthermore, InitFS, the entry point to initialize HFS, includes multiple checks for a 128K Mac, and allocates fewer file control blocks and smaller caches if so. Thus it seems fairly certain that compatibility with the Mac 128K was originally a goal for HFS.

And it looks like the solution to allow the Hard Disk 20 to load on a Mac 128K is to merely replace the memory size check with some NOP instructions.


Defeat the Memory Check

With a hex editor, it's simple to defeat the memory check by overwriting the instruction with a NOP. I always use FEdit by John Mitchell. In FEdit, choose Open File... from the File menu. Open the System file.

Now if you are editing the System file version 2.1, the code you are looking for is in the Data fork, so you need to choose Data Fork from the Options menu. System file versions 3.0 and later have the target code in the Resource Fork, so you don't need to switch forks.

Press Command-F to perform a Hex search. Enter the following:
Code:
0C 78 00 08 01 08 6D 00 01 BA
These 10 bytes are the 68000 machine language code for the CMPI.W and BLT instructions that test memory size and branch if less than 512K.

The screenshot below shows this sequence of code in the System 2.1 data fork. This identical sequence is found in the resource fork of System file versions 3.0, 3.1, 3.2, and 3.3. Later System file versions have slightly different branch offsets, so just search for the first 4 hex bytes, 0C 78 00 08, if you want to patch System versions 4.0 or later. Though it's probably a pointless waste of time to patch anything newer than 3.0 or 3.1, as you'll have even more work to do massaging the System file to work in only 128K of RAM.


Locating the machine language code for memory check


Now here is the patch. There are 10 bytes total. You need to replace them with the machine language instruction for NOP which is 4E71. This NOP will be repeated five times.

The screenshot below shows the result, again in System version 2.1. Press Command-W to write this modified sector back to disk. Click OK when asked if you are sure.


Memory check in the System file patched out with NOP instructions

And now for the moment of truth! Use this patched HD20 startup disk to boot your Mac 128K. If everything went according to plan, the Hard Disk 20 message should appear in the Welcome to Macintosh dialog box.

What? No message? Mad It's true; this patch isn't enough. There is some other factor that we've overlooked.


Expanding the System Heap

Here's what we didn't account for: the system heap. This is where ROM patches, operating system data structures, and common resources that are used by every application are stored. The application heap is cleared and initialized every time you start a new application, but the system heap sticks around. In older System versions its size is static, fixed at boot time. By the late 1980s, with System 4.2, the system heap could grow as needed.

Parameters in the boot blocks set the system heap size based on the total memory of the Mac. There are entries for a 128K, 256K (!), and 512K Mac. The entry for a Mac 128K is 17,152 bytes, or 16 and three-quarters kilobytes.

The Hard Disk 20 file is a big one! It's exactly 32,768 bytes. That's twice the size of the Mac 128K's system heap. No wonder the Hard Disk 20 file won't load! The operating system is silently refusing to load the oversized PTCH patch resources it contains into the system heap. To be exact, it's PTCH ID 0 for RAM-based HFS, which is over 24K, that is too big to load into the system heap.

We need to expand the system heap! Back to FEdit.

This time, we need to modify the boot blocks of the Hard Disk 20 Startup disk. FEdit has an editor built-in. In FEdit, choose Open Volume... from the File menu. Select your startup disk and click the Open button.

From the File menu, choose Edit Boot Blocks. At the bottom of the dialog that appears are two fields for System Heap Size. The values are in hexadecimal. The first one marked (128K) is the one to change. Its value should currently read 4300.

Enter C000, the same heap size as for a Mac 512K. This will yield a 48K system heap. Click Update to write this modified boot block.


Using FEdit's boot blocks editor to enlarge the System heap size for a Mac 128K


Let's reflect on what we've done. At 48K, the system heap is now 37.5% of the total RAM in a Mac 128K. How much free memory will be left for the application heap? The screen buffer is 22K. About 2K are used for low memory globals, including the trap dispatch table and 68000 vectors.

128K - 48K - 22K - 2K = 56K free for applications

Ouch, that's a crunch. Now you can understand why Apple decided to exclude the Mac 128K from loading the Hard Disk 20 file.


Did It Work?

Restart your Mac 128K with this patched HD20 Startup disk. Make sure you hold down the mouse button at the Welcome to Macintosh dialog to prevent the Hard Disk 20 from taking over startup. This time, you will see the "Hard Disk 20 Startup" message in the Welcome to Macintosh dialog box, signifying that both HFS and the new Sony disk driver are loaded into memory.

But then you will get a System Bomb with ID = 15. That's a Segment Loader error, and it means there's not enough free memory to load the Finder. Here's another reason why the Mac 128K was cut off from the Hard Disk 20!

However, the Finder isn't necessary. We can specify another application to run at startup, again by editing the boot blocks using FEdit. This application should be small enough to fit into the squeezed application heap, yet have commands for opening and/or saving files so we can see if HFS is truly loaded, and access the HD20.

Two applications I tried were BinHex and TeachText 1.1. You will need to experiment with different applications and different system heap sizes. If you are still getting bombs, try using FEdit again to reduce the system heap to $A300, which is 40K.


Opening a file on a Hard Disk 20 in TeachText with a Mac 128K


I would like to hear from someone who has a Mac 128K and is willing to experiment with this procedure. To summarize, it is:
  1. Copy the Hard Disk 20 Startup disk to a new disk
  2. Patch the System file to ignore the 128K memory size check
  3. Edit the boot blocks to increase the 128K system heap size
  4. Change the startup application to something smaller

When starting up from your modified HD20 Startup disk, be sure to always hold the mouse button down to prevent the Hard Disk 20's boot blocks and System from taking over.


Pseudo 128K Boot Blocks on a Mac 512K

Because I don't have a Mac 128K, I did my experiments using pseudo 128K boot blocks. Larry Kenyon's Disk Copy/Utility application has an undocumented feature: hold Command and Option while you click the wr boot block button. This will install a custom boot block that makes your Mac 512K look like it only has 128K of RAM. It reduces the size of the application heap.


"Suedo" boot blocks written (note the typo above)


After you install the pseudo 128K boot blocks, you will need to use FEdit to modify the system heap size and set the initial application to run. If you have a real Mac 128K, you don't need pseudo boot blocks.


That's as far as I can go on this topic. I'm relying on some readers who have a Mac 128K at home to take 30 minutes or so to try this and see if it works. If you can at least see a list of files in an Open dialog box from the Hard Disk 20, I'd like to hear from you. Please post your findings below. The next Mac 512K Blog article will take a look at Microsoft Multiplan and the Apple M0120 numeric keypad attachment.


The Mac 512K Blog wrote:
This blog chronicles the Macintosh 512K and my projects with it. We will test software, fix hardware, program it, hack it, and generally take the 512K Macintosh to its limits.

Do leave any feedback you may have by posting a comment to this article.


« Essential References for Macintosh Programming   •   Microsoft Multiplan for Macintosh »

Category tags: Hardware, Hacking

Comments

crutch
Member
53
Offline 
Post 16 May 2020 5:39 pm   

Near miss

Nice post. I tried this today, with only partial success:

First of all, I’m not sure which System version I have on my HD-20 Startup Disk: how do you tell? My System file has a Modified date of 6/2/86 which would be System 3.2 if Wikipedia is to be believed. But the 10-byte sequence was not the same as you listed above, I believe the first 6 bytes were the same but neglected to write them down before I modified them.

Before starting my modifications, I had booted my 128k from the HD-20 Startup Disk and chose “Use MiniFinder...”, then added a MiniFinder to my HD-20 Startup Disk, thinking it’s probably the smallest possible application that can pull up an SFGetFile dialog.

I used FEdit Plus (1986) instead of the original FEdit. In FEdit Plus, the system heap size is in decimal and so must be set to 49152 instead of $C000.

When I start up my 128k Mac, the following things happen:

If I connect my HD-20 and DON’T hold down the mouse button, I see the “HD 20 Startup” message (cool!), I hear my HD-20 activate and start clicking, the floppy ejects as it should ... then I hear a machine-gun sound as my screen goes haywire and the system crashes irrecoverably. Oh well, you warned us to hold the mouse button down ....

If I DO hold the mouse button down (or just start up from this floppy with the HD-20 not powered up), I see the “HD 20 Startup” message, but then I get a system bomb with ID = 28 (stack collision with heap). So, I’ve taken too much heap space with my giant system heap? I can’t see MiniFinder being big enough to cause this problem, I wonder what’s going on.

I tried this again with the system heap shrunk to 40k — same thing.

So I tried using TeachText instead of MiniFinder. That time, the application seemed to load — I saw an Apple, File, and Edit menu appear. Then, however, a disembodied disk swap icon mysteriously appeared near the Apple menu and I got a system bomb, address error.

So I never had the opportunity to actually verify file access to the HD20 would work.

Oh well, it was fun trying.

Guest
Member
868
Post 15 Aug 2020 6:21 pm   

My experience with a real 128K is totally similar to the one reported above. With TeachText, it’s been impossible to find the right size for the heap. With BinHex 2.1 and a heap size of 40K, I could get to the file picker and the HD20 was there, selectable. However, the application crashed soon after the file got selected and there I stopped.
In the end, interesting hack, but totally pointless purpose, as it’s just not possible to make anything useful out of it. Good fun and good learning, though.

paolo_bertolo
Member
100
Offline 
Post 15 Aug 2020 6:23 pm   

My experience with a real 128K is totally similar to the one reported above. With TeachText, it’s been impossible to find the right size for the heap. With BinHex 2.1 and a heap size of 40K, I could get to the file picker and the HD20 was there, selectable. However, the application crashed soon after the file got selected and there I stopped.
In the end, interesting hack, but totally pointless purpose, as it’s just not possible to make anything useful out of it. Good fun and good learning, though.

Dog Cow
Magician Magician

21218
Offline 
Post 19 May 2022 5:40 pm   

Since writing this article, I now have my own Mac 128K. I will resume experimentation and post any results that I may have.




Moof! Moof! Dogcow!

Book: The New Apple II User's Guide
Guest
Member
868
Post 21 Jan 2023 12:32 pm   

I've done my own prodding with a 128k (real and emulated) and I've found that MFS can support 10mb drives.

Also I believe a Macintosh plus can boot from a MFS formatted HD20 (in this case, a floppy emu, I tested this a while back so I might be misremembering)

128k Mini vMac also can boot quite happily from 10mb MFS floppy images.

So could we eek out a bit more RAM by targeting an MFS formatted HD20, or am I missing something obvious here?

Dog Cow
Magician Magician

21218
Offline 
Post 22 Jan 2023 4:13 pm   

Guest wrote:
I've done my own prodding with a 128k (real and emulated) and I've found that MFS can support 10mb drives.

Yes, the earliest hard drives for Macintosh in 1984 supported 5 and 10 MB volume sizes on MFS, before HFS was introduced.


Also I believe a Macintosh plus can boot from a MFS formatted HD20 (in this case, a floppy emu, I tested this a while back so I might be misremembering)

That's not conclusive, as the Floppy Emu may differ from a genuine Hard Disk 20.


128k Mini vMac also can boot quite happily from 10mb MFS floppy images.
And you can boot a Mac 512K or 128K from an 800K MFS floppy disk. As long as the Sony disk driver in ROM can read blocks from the device, and the volume is MFS-formatted, the Mac can boot from it.


So could we eek out a bit more RAM by targeting an MFS formatted HD20, or am I missing something obvious here?

Yes, that is a possible strategy. You'd still need to use the Hard Disk 20 Startup disk on a Mac with 64K ROM, regardless of whether the HD20 was formatted as MFS or HFS.


Concluding note: I have a Mac 128K now, since I wrote this article in 2019, and I want to continue experimenting with HFS and the Hard Disk 20, but I have no more free time to do it right now. Neutral




Moof! Moof! Dogcow!

Book: The New Apple II User's Guide
Quick Reply